package com.uk.ui.windows;

import java.util.List;

import com.uk.data.containers.FaturaContainer;
import com.uk.data.entities.Fatura;
import com.uk.data.entities.Kontrata;
import com.uk.interfaces.PopupWindowListener;
import com.uk.myclasses.ATable;
import com.uk.ui.PopupWindow;
import com.uk.ui.fatura.KontrataInfo;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;

public class Fatura2SelectWindow extends  PopupWindow implements ValueChangeListener {

	private PopupWindowListener listener;
	private Fatura selectedFatura;
	
	
	
	
	
	public Fatura2SelectWindow(PopupWindowListener listener, Kontrata kontrata,List<Fatura> faturaList){
		
		super("Kontrata dhe fatura e papaguara", "600px", "400px");
		this.center();
		this.listener = listener;
		KontrataInfo kontraInfo = new KontrataInfo();
		kontraInfo.loadKontrata(kontrata);
		this.addComponent(kontraInfo);
		FaturaContainer faturaContainer = new FaturaContainer( faturaList);
		ATable table = new ATable();
		table.setContainerDataSource(faturaContainer);
		table.setVisibleColumns(new Object[]{"id","dataLeximAktual","leximiAktual"});
		table.setColumnHeaders(new String[]{"ID","Data","Leximi"});
		
		table.setPageLength(5);
		table.setSelectable(true);
		table.setImmediate(true);
		table.setSortDisabled(true);
		table.setWidth("550px");
		table.setSelectable(true);
		table.setImmediate(true);
		table.addListener(this);
		this.addComponent(table);
		
		
		System.out.println("Fatura2SelectWindow.Fatura2SelectWindow()");
		
	}

	@Override
	public void valueChange(ValueChangeEvent event) {
		
		this.selectedFatura = (Fatura) event.getProperty().getValue();
		this.listener.returnAction(this);
		this.close();
		
	}
	public Fatura getSelectedFatura() {
		return selectedFatura;
	}
}
